﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class SuperAdminMainForm : Form
    {
        string uname;

        public SuperAdminMainForm(string uname)
        {
            InitializeComponent();
            this.uname = uname;
        }
        string GetRstr(string sql)
        {
            string str = null;
            string connectionString = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            SqlDataReader r = cmd.ExecuteReader();
            if (r.Read())
            {
                str = r.GetString(0);
            }
            r.Close();
            con.Close();
            return str;
        }

        private void SuperAdminMainForm_Load(object sender, EventArgs e)
        {
            string sql = string.Format("select 姓名 from 公寓管理员信息表 where 管理员ID='{0}'", uname);
            toolStripStatusLabel1.Text += GetRstr(sql);
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("你确定要退出吗?","提示",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                System.Environment.Exit(System.Environment.ExitCode);
                this.Dispose();
                this.Close();
            }
        }

        private void 关于系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutSystem absys = new AboutSystem();
            absys.MdiParent = this;
            absys.Show();
        }

        private void 添加学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddStuInfo addstu = new AddStuInfo();
            addstu.MdiParent = this;
            addstu.Show();
        }

        private void 删除学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DelStuInfo delstu = new DelStuInfo();
            delstu.MdiParent = this;
            delstu.Show();
        }

        private void 修改学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StuInfoModify mdstu = new StuInfoModify();
            mdstu.MdiParent = this;
            mdstu.Show();
        }

        private void 查询学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StuInfoSeek stsk = new StuInfoSeek();
            stsk.MdiParent = this;
            stsk.Show();
        }

        private void 增加管理员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddAdmin adm = new AddAdmin();
            adm.MdiParent = this;
            adm.Show();
        }

        private void 删除管理员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DelAdmin delam = new DelAdmin();
            delam.MdiParent = this;
            delam.Show();
        }

        private void 修改管理员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ModifyAdmin mam = new ModifyAdmin();
            mam.MdiParent = this;
            mam.Show();
        }

        private void 查询管理员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SeekAdmin sam = new SeekAdmin();
            sam.MdiParent = this;
            sam.Show();
        }
    }
}
